#!/bin/bash

dl_path='/basic/go'

dl_unzip() {
  mkdir -p $dl_path
  cd $dl_path || exit
  local tarFile
  tarFile='go1.17.tar.gz'
  wget -O $tarFile https://dl.google.com/go/go1.17.2.linux-amd64.tar.gz

  if [ -e $tarFile ]; then
    tar -zxvf $tarFile
    mv go go1.17
    rm -rf $tarFile

  else
    echo '下载go压缩包失败'
    exit
  fi
}

edit_path() {
  local profile
  profile='/etc/profile'
  #\cp 如果已存在，直接覆盖，不询问
#  \cp $profile profile.go_install.bk
  #'EOF'禁止转义
  cat << 'EOF' >> $profile

export GOPATH=/basic/go/go1.17
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH/bin
export GOPROXY="https://goproxy.io,direct"
EOF

  source '/etc/profile'
  go version
}

dl_unzip
edit_path